clear
set more off


**********************
**1986 Social Survey**
**********************

use "$base\Raw Data Files\UG8601.dta"


*Voting was mandatory in the 1983 parliamentary elections in Voralberg, Tyrol and Styria
gen CV=1 if bld==1 | bld==2 | bld==6
replace CV=0 if CV==.

*Drop people who were not of the voting age (those who are less than 22 were less than 19 in 1986)
gen age=alter
drop if age<22

gen voted=(d12==1)
replace voted=. if d12==.

*Preference for left parties if prefers KPO or SPO, preference for right parties if prefers FPO or OVP
gen party_pref_left=(d11==1 | d11==7)
gen party_pref_right=(d11==2 | d11==3)
gen party_pref_other=(d11>2 & d11<9 & d11!=3 & d11!=7)
gen party_pref_none=(d11==9)
gen party_pref_missing=(d11==.)

gen reads_newspaper=(e5==1)
replace reads_newspaper=. if e5==.

*Recode the interest in politics variable
gen polit_inter=1 if d9>3
replace polit_inter=2 if d9==3
replace polit_inter=3 if d9<3
replace polit_inter=. if d9==.

gen party_member=(d10b==1)
replace party_member=. if d10b==.

gen region=bld
gen HH_income=heink
gen male=(sex==1)
replace male=. if sex==.
gen works=(a8==1)
replace works=. if a8==.
gen unempl=(a8==2)
replace unempl=. if a8==.
gen pensioneer=(a8==3)
replace pensioneer=. if a8==.
gen indiv_income=a15
gen wave2=0
gen community_size=ortsgr
gen HH_size=h34
gen HH_aged_below16=HH_size-h30
gen schooling=a1
gen schooling_father=a3
gen schooling_mother=a4

keep  CV schooling schooling_father schooling_mother party_pref_left party_pref_right voted party_pref_other party_pref_none party_pref_missing reads_newspaper polit_inter party_member region HH_income male age unempl works pensioneer indiv_income wave2 community_size HH_size HH_aged_below16 

save "$base\ASS_86.dta", replace

**********************
**2003 Social Survey**
**********************

clear
use "$base\Raw Data Files\ug0301.dta"

*No states had CV in parliamentary elections by 2002
gen CV=0


**Drop if not of the voting age in 2002 (<18 age at time of the election, so <19 now)
drop if Alter<19


gen voted=(h13203==1)
*Voted missing if he/she doesn't specify whether participated in election
replace voted=. if h13203==3

*Preference for left parties if prefers SPO, preference for right parties if prefers FPO or OVP
gen party_pref_left=(h13103==1)
replace party_pref_left=. if h13103==.
gen party_pref_right=(h13103==2 | h13103==3)
replace party_pref_right=. if h13103==.
gen party_pref_other=( h13103==4 | h13103==5)
replace party_pref_other=. if h13103==.
gen party_pref_none=(h13103==6)
replace party_pref_none=. if h13103==.
gen party_pref_missing=(h13103==7 | h13103==.)

gen reads_newspaper=(d7203==1)
replace reads_newspaper=. if d7203==3

gen polit_inter=1 if f8903>3
replace polit_inter=2 if f8903==3
replace polit_inter=3 if f8903<3
replace polit_inter=. if f8903==6

gen party_member=(f90b03<3)
replace party_member=. if f90b03==4

gen region=bdland
gen HH_income=h12403
replace HH_income=. if h12403==22
gen male=(Geschlecht==1)
replace male=. if Geschlecht==.
gen age=Alter
gen works=(a1103==1)
replace works=. if a1103==.
gen unempl=(a1103==3)
replace unempl=. if a1103==.
gen pensioneer=(a1103==4)
replace pensioneer=. if a1103==.
gen indiv_income=h12303
replace indiv_income=0 if h12303==23
replace indiv_income=. if h12303==22
gen wave2=1
gen community_size=ortsgr03
gen HH_size=hhc03
gen HH_aged_below16=HH_size-hhcd03
gen schooling=a103
gen schooling_father=a303
gen schooling_mother=a403


keep CV schooling schooling_father schooling_mother party_pref_left party_pref_right voted  party_pref_other party_pref_none party_pref_missing reads_newspaper polit_inter party_member region HH_income male age unempl works pensioneer indiv_income wave2 community_size HH_size HH_aged_below16
append using "$base\ASS_86.dta"


gen age_2=age*age
label variable age_2 "Age squared"
gen comm_size_recoded=1 if community_size<4
replace comm_size_recoded=2 if community_size==4 | community_size==5 | community_size==6
replace comm_size_recoded=3 if community_size>6
label variable comm_size_recoded "Community Size - 3 categories"

foreach x in 1 2 3{
gen comm_size_`x'=(comm_size_recoded ==`x')
}



*Make region codes consistent with the aggregate data
gen state_code=1 if region==7
replace state_code=2 if region==5
replace state_code=3 if region==4
replace state_code=4 if region==8
replace state_code=5 if region==3
replace state_code=6 if region==6
replace state_code=7 if region==2
replace state_code=8 if region==1
replace state_code=9 if region==9


forvalues x=1/9{
gen state_code_`x'=(state_code==`x')
}


label define state_lbl 1 "Burgenland" 2 "Carinthia" 3 "Lower Austria" 4 "Upper Austria"  5 "Salzburg" 6 "Styria" 7 "Tyrol" 8 "Vorarlberg" 9 "Vienna"
label values state_code state_lbl
label variable state_code "State"



**Generate Interactions and Group Variables

** Gender
gen female=(male==0)
gen female_CV=female*CV
gen male_CV=male*CV

** Education
gen compulsory_schooling=(schooling==1 | schooling==2)
gen vocational_mschool=(schooling==3)
gen academic_hschool=(schooling==4 | schooling==5)
gen college=(schooling==6)
gen hschool_more=academic_hschool+college

gen compulsory_schooling_f=(schooling_father==1|schooling_father==2)
gen vocational_mschool_f=(schooling_father==3)
gen hschool_more_f=schooling_father==4 | schooling_father==5 | schooling_father==6

gen compulsory_schooling_m=(schooling_mother==1|schooling_mother==2)
gen vocational_mschool_m=(schooling_mother==3)
gen hschool_more_m=schooling_mother==4 | schooling_mother==5 | schooling_mother==6


foreach x of  varlist   compulsory_schooling vocational_mschool academic_hschool college hschool_more {
replace `x'=. if schooling==.
gen `x'_CV=`x'*CV
}

drop academic_hschool_CV college_CV

foreach x of  varlist  compulsory_schooling_f vocational_mschool_f hschool_more_f {
replace `x'=. if schooling_father==.|schooling_father==7

}

foreach x of  varlist  compulsory_schooling_m vocational_mschool_m hschool_more_m{
replace `x'=. if schooling_mother==.|schooling_mother==7
}


  
** Income Quintile

*Attribute the mid-point, then divide by HH_size, and built categories according to quintiles
gen mid_HH_income=180 if wave2==1 & HH_income==1
replace mid_HH_income=385 if wave2==1 & HH_income==2
replace mid_HH_income=525 if wave2==1 & HH_income==3
replace mid_HH_income=675 if wave2==1 & HH_income==4
replace mid_HH_income=825 if wave2==1 & HH_income==5
replace mid_HH_income=975 if wave2==1 & HH_income==6
replace mid_HH_income=1125 if wave2==1 & HH_income==7
replace mid_HH_income=1275 if wave2==1 & HH_income==8
replace mid_HH_income=1425 if wave2==1 & HH_income==9
replace mid_HH_income=1575 if wave2==1 & HH_income==10
replace mid_HH_income=1725 if wave2==1 & HH_income==11
replace mid_HH_income=1875 if wave2==1 & HH_income==12
replace mid_HH_income=2025 if wave2==1 & HH_income==13
replace mid_HH_income=2175 if wave2==1 & HH_income==14
replace mid_HH_income=2325 if wave2==1 & HH_income==15
replace mid_HH_income=2550 if wave2==1 & HH_income==16
replace mid_HH_income=2850 if wave2==1 & HH_income==17
replace mid_HH_income=3150 if wave2==1 & HH_income==18
replace mid_HH_income=3450 if wave2==1 & HH_income==19
replace mid_HH_income=3750 if wave2==1 & HH_income==20
replace mid_HH_income=4200 if wave2==1 & HH_income==21

replace mid_HH_income=3000 if wave2==0 & HH_income==1
replace mid_HH_income=5000 if wave2==0 & HH_income==2
replace mid_HH_income=7000 if wave2==0 & HH_income==3
replace mid_HH_income=9000 if wave2==0 & HH_income==4
replace mid_HH_income=11000 if wave2==0 & HH_income==5
replace mid_HH_income=13000 if wave2==0 & HH_income==6
replace mid_HH_income=15000 if wave2==0 & HH_income==7
replace mid_HH_income=17000 if wave2==0 & HH_income==8
replace mid_HH_income=19000 if wave2==0 & HH_income==9
replace mid_HH_income=21000 if wave2==0 & HH_income==10
replace mid_HH_income=23000 if wave2==0 & HH_income==11
replace mid_HH_income=25000 if wave2==0 & HH_income==12
replace mid_HH_income=27000 if wave2==0 & HH_income==13
replace mid_HH_income=29000 if wave2==0 & HH_income==14
replace mid_HH_income=31000 if wave2==0 & HH_income==15
replace mid_HH_income=33000 if wave2==0 & HH_income==16
replace mid_HH_income=35000 if wave2==0 & HH_income==17
replace mid_HH_income=37000 if wave2==0 & HH_income==18
replace mid_HH_income=39000 if wave2==0 & HH_income==19
replace mid_HH_income=41000 if wave2==0 & HH_income==20


/*How to calculate the equivalised household size
1.0 to the first adult;
0.5 to the second and each subsequent person aged 14 and over;
0.3 to each child aged under 14.
*/

gen HH_size_eq=1+0.5*(HH_size-1-HH_aged_below16)+ 0.3*HH_aged_below16 

gen equivalised_income=mid_HH_income/HH_size_eq
gen equivalised_income_euros=equivalised_income if wave2==1
replace equivalised_income_euros=(mid_HH_income/13.7603)/HH_size_eq if wave2==0

*In 2003 Euros (1 ATS in 1986 = 0.1059 Euros in 2003)
gen mid_HH_income_euros=mid_HH_income if wave2==1
replace mid_HH_income_euros=mid_HH_income*0.1059 if wave2==0

gen income_Q1=0
gen income_Q2=0
gen income_Q3=0
gen income_Q4=0

foreach x in 0 1{
sum equivalised_income if wave2==`x', detail
replace income_Q1=1 if equivalised_income<=r(p25) & wave2==`x'
replace income_Q2=1 if equivalised_income>r(p25) & equivalised_income<=r(p50) & wave2==`x'
replace income_Q3=1 if equivalised_income>r(p50) & equivalised_income<=r(p75) & wave2==`x'
replace income_Q4=1 if equivalised_income>r(p75) & wave2==`x' 
}

replace income_Q1=. if equivalised_income==.
replace income_Q2=. if equivalised_income==.
replace income_Q3=. if equivalised_income==.
replace income_Q4=. if equivalised_income==.


foreach x in 1 2 3 4{
replace income_Q`x'=. if HH_income==.
gen income_Q`x'_CV=CV*income_Q`x'
 }
 
 
** Political party membership	
gen not_party_member=(party_member==0)
replace not_party_member=. if party_member==.

gen not_party_member_CV=not_party_member*CV		  
gen party_member_CV=party_member*CV		
  

** Degre of Information
gen doesnt_read_newspaper=1 if reads_newspaper==0
replace doesnt_read_newspaper=0 if reads_newspaper==1
gen doesnt_read_newspaper_CV =doesnt_read_newspaper*CV 		
gen reads_newspaper_CV =reads_newspaper*CV 		


** Interest in Politics
 
foreach x in 1 2 3{
gen polit_inter_`x'=(polit_inter ==`x')
replace polit_inter_`x'=. if polit_inter==.
gen polit_inter_`x'_CV=polit_inter_`x'*CV

}

**  Self reported political preferences 
foreach x in left right none other{
replace party_pref_`x'=. if party_pref_missing==1		
gen party_pref_`x'_CV=party_pref_`x'*CV
}

drop   polit_inter  indiv_income community_size  party_pref_missing HH_aged_below16  schooling schooling_father schooling_mother comm_size_recoded mid_HH_income HH_size_eq equivalised_income equivalised_income_euros  HH_income  region


**** Clean the database with just the stuff we use and appropriate labels

egen missing_controls=rowmiss(voted  age age_2 female  compulsory_schooling vocational_mschool academic_hschool college compulsory_schooling_f vocational_mschool_f compulsory_schooling_m vocational_mschool_m hschool_more hschool_more_f hschool_more_m HH_size  comm_size_1 comm_size_2  works pensioneer  party_pref_left party_pref_right party_pref_none party_pref_other    doesnt_read_newspaper not_party_member  polit_inter_1 polit_inter_2 polit_inter_3  wave2 state_code)

gen sample_with_controls=(missing_controls==0)
label variable sample_with_controls "Sample with non-missing values for voting and controls"
drop missing_controls


** Make the age variable be at the time of the election
replace age=age-3 if wave2==0
replace age=age-1 if wave2==1
drop age_2
gen age_2=age*age



label variable voted "=1 if voted in last parliamentary election"
label variable CV "=1 if voting was compulsory in last parliamentary election"
label variable age "Age"
label variable age_2 "Age (squared)"
label variable female "=1 if female"
label variable male "=1 if male"
label variable compulsory_schooling "=1 if maximum education is compulsory schooling"
label variable vocational_mschool "=1 if maximum education is vocational middle school"
label variable academic_hschool "=1 if maximum education is high school"
label variable college "=1 if maximum education is college"
label variable hschool_more "=1 if maximum education is high school or college"
label variable income_Q1 "=1 if income in quartile 1"
label variable income_Q2 "=1 if income in quartile 2"
label variable income_Q3 "=1 if income in quartile 3"
label variable income_Q4 "=1 if income in quartile 4"
label variable mid_HH_income_euros "Household Income (in 2003 Euros)"
label variable party_member "=1 if member of a political party"
label variable not_party_member "=1 if not a member of a political party"
label variable reads_newspaper "=1 if regularly reads newspaper"
label variable doesnt_read_newspaper "=1 if doesn't read newspaper regularly"
label variable party_pref_left "=1 if party preference = left"
label variable party_pref_right "=1 if party preference = right"
label variable party_pref_other "=1 if party preference = minor parties"
label variable party_pref_none "=1 if no party preference"
label variable polit_inter_1 "=1 if uninterested in politics"
label variable polit_inter_2 "=1 if mildly Interested in politics"
label variable polit_inter_3 "=1 if very interested in politics "
label variable works "=1 if employed"
label variable unempl "=1 if unemployed"
label variable pensioneer "=1 if retired"
label variable HH_size "Number of members in household"
label variable  comm_size_1 "Community population - small"
label variable  comm_size_2 "Community population - medium"
label variable compulsory_schooling_f "=1 if father's maximum education is compulsory schooling"
label variable compulsory_schooling_m "=1 if mother's maximum education is compulsory schooling"
label variable vocational_mschool_f  "=1 if father's maximum education is vocational middle school"
label variable vocational_mschool_m  "=1 if mother's maximum education is vocational middle school"
label variable  hschool_more_f "=1 if father's maximum education is high school or college"
label variable  hschool_more_m "=1 if mother's maximum education is high school or college"
label variable  female_CV  "Female * CV"
label variable  male_CV  "Male * CV"
label variable compulsory_schooling_CV "Compulsory schooling * CV"
label variable vocational_mschool_CV "Vocational middle school * CV"
label variable hschool_more_CV "High school of college * CV"
label variable income_Q1_CV "Income Q1 * CV"
label variable income_Q2_CV"Income Q2 * CV"
label variable income_Q3_CV "Income Q3 * CV"
label variable income_Q4_CV "Income Q4 * CV"
label variable party_member_CV "Party member * CV"
label variable not_party_member_CV "Not a party member * CV"
label variable  reads_newspaper_CV  "Reads newspaper * CV"
label variable doesnt_read_newspaper_CV "Doesn't read newspaper * CV"
label variable polit_inter_1_CV "Uninterested in politics * CV"
label variable polit_inter_2_CV "Mildly interested in politics * CV"
label variable polit_inter_3_CV "Very interested in politics * CV"
label variable party_pref_left_CV "Party preference for left * CV"
label variable party_pref_right_CV "Party preference for right * CV"
label variable party_pref_other_CV "Party preference for minor parties * CV"
label variable party_pref_none_CV "No party preference * CV"

save	"$base\ASS.dta", replace





